
#include <string.h>
#include <stdlib.h>
#include "debug.h"
#include "SQLiteInterface.h"

SQLiteInterface::SQLiteInterface()
{
   sqlite3_initialize();
   if (!(sqlite3_threadsafe()))
      errprint("Thread safety off?!?! Please recompile SQLite with thread safety on.");
}

SQLiteInterface::~SQLiteInterface()
{
   sqlite3_shutdown();
}

void SQLiteInterface::SQLiteErrorMessage(sqlite3 *sdb, const char *message, const char *fpretty, int line)
{
   const char *errmsg = sqlite3_errmsg(sdb);
   char *errbuf = (char *)malloc(sizeof(char)*(strlen(errmsg)+strlen(message)+1));
   if (errbuf)
   {
      memcpy(errbuf, message, sizeof(char)*(strlen(message)+1));
      memcpy(&(errbuf[strlen(message)]), errmsg, sizeof(char)*(strlen(errmsg)+1));
      errprintpd(errbuf, fpretty, line);
      free(errbuf);
   } else
   {
      errprintpd(errmsg, fpretty, line);
   }
}
